package com.huilian.iotbox.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.huilian.iotbox.admin.dao.NoticeDao;
import com.huilian.iotbox.admin.service.NoticeService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.po.Notice;
import com.huilian.iotbox.data.vo.NoticeVo;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class NoticeServiceImpl implements NoticeService {

    @Resource
    private NoticeDao noticeDao;

    @Override
    public ServerResponse findListByKeyword(UserInfo userInfo, Notice notice) {
        notice.setUserId(userInfo.getId());
        PageHelper.startPage(notice.getPageNum(), notice.getPageSize());
        List<NoticeVo> noticeVoList = noticeDao.findAllByKeyword(notice);
        PageInfo pagResult = new PageInfo(noticeVoList);
        return ServerResponse.createBySuccess(pagResult);
    }

    @Override
    public ServerResponse delete(Integer id) {
        return ServerResponse.createBySuccess(noticeDao.deleteById(id));
    }

    @Override
    public ServerResponse update(Notice notice) {
        return ServerResponse.createBySuccess(noticeDao.update(notice));
    }

    @Override
    public ServerResponse add(Notice notice) {
        return ServerResponse.createBySuccess(noticeDao.insert(notice));
    }

}
